import { ref, onMounted, onBeforeUnmount } from 'vue'

export function useMousePosition() {
  const x = ref(0)
  const y = ref(0)

  const update = (ev:MouseEvent)=>{
    x.value = ev.pageX
    y.value = ev.pageY
  }

  onMounted(()=>{
    window.addEventListener('mousemove', update)
  })

  onBeforeUnmount(()=>{
    window.removeEventListener('mousemove', update)
  })

  return [x, y] as const
}


